<template>
    <div class="">
        <div class="system-user-search mb15">
				<el-select
    v-model="nameandid"
    filterable
    allow-create
    default-first-option
    placeholder="请选择文章科室或输入手术名称">
    <el-option
      v-for="item in departmentClassData"
      :key="item.dpcId"
      :label="item.dpcName"
      :value="item.dpcId">
    </el-option>
  </el-select>
				<el-button size="default" type="primary" @click="list()" class="ml10">
					<el-icon>
						<ele-Search />
					</el-icon>
					查询
				</el-button>

				<el-button size="default" type="success" @click="onOpenAddPati()" class="ml10">
					<el-icon>
						<ele-FolderAdd />
					</el-icon>
					新增手术类型
				</el-button>
			</div>
      <el-table
    :data="pagination.records"
    border 
    style="width: 100%">
     <el-table-column  prop="hoyId"  label="手术id"   width="300">  </el-table-column>
     <el-table-column  prop="hoyName"  label="手术名称"   width="300">  </el-table-column>
     <el-table-column  prop="departmentClass.dpcName"  label="科室"   width="300">  </el-table-column>
     <el-table-column prop="hoyPrice" label="手术费" width="220"> </el-table-column>
    <el-table-column  prop="hoyPriceWorker" label="人工费"    width="350"> </el-table-column>
    <el-table-column prop="hoyStatus" label="状态" show-overflow-tooltip>
					<template #default="scope" >
						<el-tag type="success"  v-if="scope.row.hoyStatus=='y'" @click="upStats(scope.row)" >启用</el-tag>
						<el-tag type="info" v-else @click="upStats(scope.row)" >禁用</el-tag>
					</template>
				</el-table-column>
    <el-table-column fixed="right"  label="操作" width="100">
      <template slot-scope="scope">
     <el-button @click="del(scope.row)"  type="text" size="small">删除</el-button>
    <el-button type="text" size="small" @click="upUI(scope.row)">编辑</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div class="block">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :hide-on-single-page="true"
      :current-page="pagination.current"
		  :page-sizes="[3,5,8,10]"
		  :page-size="pagination.size"
		  layout="total,sizes, prev, pager, next, jumper"
		  :total="pagination.total">
    </el-pagination>
  </div>
      <el-dialog title="添加手术类型" :visible.sync="addTag" :close-on-click-modal="false">
			  <el-form :model="addTypeForm" size="small" label-width="90px">
				<el-row :gutter="35">
          
           <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="手术名称">
							<el-input v-model="addTypeForm.hoyName" placeholder="请输入手术名称" clearable></el-input>
						</el-form-item>
					</el-col>

                 <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="科室类型">
							<el-select v-model="addTypeForm.hdcId" placeholder="请选择"  style="width:100%"  >
            <el-option
             v-for="item in departmentClassData"
              :key="item.dpcId"
              :label="item.dpcName"
              :value="item.dpcId">
            </el-option>
           </el-select>
						</el-form-item>
					</el-col>

              <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="手术费">
							<el-input v-model="addTypeForm.hoyPrice" placeholder="请输入手术费" clearable></el-input>
						</el-form-item>
					</el-col>


           <el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="人工费">
							<el-input v-model="addTypeForm.hoyPriceWorker"  placeholder="请输入人工费" clearable></el-input>
						</el-form-item>
					</el-col>

	            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="付费状态">
							<el-switch v-model="addTypeForm.hoyStatus" active-value="y" inactive-value="n" inline-prompt active-text="是" inactive-text="否"></el-switch>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
      <template #footer>
				<span class="dialog-footer">
					<el-button @click="onCancel" size="default">取 消</el-button>
					<el-button type="primary" @click="onSubmit" size="default">新 增</el-button>
				</span>
			</template>
			</el-dialog>


 <el-dialog title="修改手术类型" :visible.sync="upTag" :close-on-click-modal="false">
			  <el-form :model="upTypeForm" size="small" label-width="90px">
				<el-row :gutter="35">
          
           <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="手术名称">
							<el-input v-model="upTypeForm.hoyName" placeholder="请输入手术名称" clearable></el-input>
						</el-form-item>
					</el-col>

                 <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="科室类型">
							<el-select v-model="upTypeForm.hdcId" placeholder="请选择"  style="width:100%"  >
            <el-option
             v-for="item in departmentClassData"
              :key="item.dpcId"
              :label="item.dpcName"
              :value="item.dpcId">
            </el-option>
           </el-select>
						</el-form-item>
					</el-col>

              <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="手术费">
							<el-input v-model="upTypeForm.hoyPrice" placeholder="请输入手术费" clearable></el-input>
						</el-form-item>
					</el-col>


           <el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="人工费">
							<el-input v-model="upTypeForm.hoyPriceWorker"  placeholder="请输入人工费" clearable></el-input>
						</el-form-item>
					</el-col>

	            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="付费状态">
							<el-switch v-model="upTypeForm.hoyStatus" active-value="y" inactive-value="n" inline-prompt active-text="是" inactive-text="否"></el-switch>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
      <template #footer>
				<span class="dialog-footer">
					<el-button @click="uponCancel" size="default">取 消</el-button>
					<el-button type="primary" @click="uponSubmit" size="default">修 改</el-button>
				</span>
			</template>
			</el-dialog>

    </div>
</template>

<script>
import optype from '@/api/optype';
export default {
    name: "doctList",
    methods:{
      //分页
        handleSizeChange(value) {
          this.pagination.size = value
          this.list(this.pagination.current,this.pagination.size);
       },
        handleCurrentChange(value) {
          this.pagination.current = value
          this.list(this.pagination.current,this.pagination.size);
       },
       del(pat){
         this.$confirm('此操作将永久删除名字为'+pat.hoyId+'的用户, 是否继续?', '提示', {
                    type: 'warning'
                    }).then(() => {
                        optype.delOptype(pat.hoyId).then(resp=>{
                             this.$message({type: 'success',message: resp.message});
                           this.list();
                        })
                    }).catch(() => {
                       this.$message({type: 'info',message: '已取消删除'});          
                    });
       } ,
   
          // 打开新增用户弹窗
		onOpenAddPati() {
             optype.getListDto().then(resp=>{
                this.departmentClassData=resp.departmentClassList;
             })
            this.addTag=true;
        },
     // 关闭新增用户弹窗
      onCancel () {
          this.addTag = false;
          this.addTypeForm={};
      },

      list(pageym=1,pagesize=8){
            optype.findOptype(pageym,pagesize,this.nameandid).then(resp=>{
               this.pagination=resp;
            });
        },
        
        onSubmit() {
       optype.addOptype(this.addTypeForm).then(resp=>{
        this.$message({type: 'success',message: resp.message});
            		this.addTag=false;
                this.addTypeForm={};
            		this.list();
       })
    },
    //修改
     uponCancel () {
         this.upTag = false;
         this.upTypeForm={};
    },
     uponSubmit () {
        optype.upOptype(this.upTypeForm).then(resp=>{
          this.$message({type: 'success',message: resp.message});
            		this.upTag=false;
            		this.upTypeForm={};
            		this.list();
       })
    },
    upStats(obj){
        if(obj.hoyStatus=='y'){
          obj.hoyStatus='n'
        }else{
        obj.hoyStatus='y'
        }
         optype.upOptype(obj).then(resp=>{
         }) 
    },
		 upUI(pat){
         optype.upOptypeui(pat.hoyId).then(resp=>{
           this.upTypeForm=resp
            optype.getListDto().then(resp=>{
                this.departmentClassData=resp.departmentClassList;
             })
            this.upTag = true;
         })
       },
       deptdto(){
         optype.getListDto().then(resp=>{
                this.departmentClassData=resp.departmentClassList;
             })
       }
    },
        data() {
      return {
        pagination:{},//分页对象
        nameandid:"",//查询参数
        addTag:false,//是否显示添加弹窗
        upTag:false,
        addTypeForm:{},//添加医嘱
        upTypeForm:{},
        departmentClassData:{},//科室列表
        patientsData:{},//患者列表
      }
        }
    ,  
    mounted() {
        this.list(1,8);
        this.deptdto();
    },
}
</script>

<style  scoped>
</style>
